package com.china.produce.config.redisson;

import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName
 * @Author niujie
 * @Version
 * @Description
 * @CreateTime 2022/11/13
 */
@Configuration
public class RedissonConfig {

    private static Logger log = LoggerFactory.getLogger(RedissonConfig.class);

    @Bean(name = "redissonClients")
    public Redisson redissonClients() {
        Config config = new Config();

        config.useSingleServer().setAddress("redis://117.72.96.70:6379").setPassword("123456").setDatabase(0);

        RedissonClient redissonClient = Redisson.create(config);

        //初始化布隆过滤器:预计元素为10000L,误判率1%
        //RBloomFilter<String> bloomFilter = redissonClient.getBloomFilter("bloom");
        //bloomFilter.tryInit(10000L, 0.01);
        //增加数据
        //bloomFilter.add("1");
        //判断指定数据是否在布隆过滤器中
        //log.info("redis bloom filter {}", bloomFilter.contains("1"));
        //log.info("redis bloom filter {}", bloomFilter.contains("666"));

        return (Redisson) redissonClient;
    }
}
